<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace Qiniu\Processing;

class PersistentFop
{
    private $auth;
    private $config;
    public function __construct($auth, $config = NULL)
    {
        $this->auth = $auth;
        if($config == NULL) {
            $this->config = new \Qiniu\Config();
        } else {
            $this->config = $config;
        }
    }
    public function execute($bucket, $key, $fops, $pipeline = NULL, $notify_url = NULL, $force = false)
    {
        if(is_array($fops)) {
            $fops = implode(";", $fops);
        }
        $params = ["bucket" => $bucket, "key" => $key, "fops" => $fops];
        Qiniu\setWithoutEmpty($params, "pipeline", $pipeline);
        Qiniu\setWithoutEmpty($params, "notifyURL", $notify_url);
        if($force) {
            $params["force"] = 1;
        }
        $data = http_build_query($params);
        $scheme = "http://";
        if($this->config->useHTTPS === true) {
            $scheme = "https://";
        }
        $url = $scheme . \Qiniu\Config::API_HOST . "/pfop/";
        $headers = $this->auth->authorization($url, $data, "application/x-www-form-urlencoded");
        $headers["Content-Type"] = "application/x-www-form-urlencoded";
        $response = \Qiniu\Http\Client::post($url, $data, $headers);
        if(!$response->ok()) {
            return [NULL, new \Qiniu\Http\Error($url, $response)];
        }
        $r = $response->json();
        $id = $r["persistentId"];
        return [$id, NULL];
    }
    public function status($id)
    {
        $scheme = "http://";
        if($this->config->useHTTPS === true) {
            $scheme = "https://";
        }
        $url = $scheme . \Qiniu\Config::API_HOST . "/status/get/prefop?id=" . $id;
        $response = \Qiniu\Http\Client::get($url);
        if(!$response->ok()) {
            return [NULL, new \Qiniu\Http\Error($url, $response)];
        }
        return [$response->json(), NULL];
    }
}

?>